<template>
  <div class="t_body">
    <jf-header @index="changeNum"></jf-header>
    <!-- <IndexContent @index="changeNum" v-show="indexShow == 1"></IndexContent>
    <MyList v-show="indexShow == 2"></MyList> -->
    <router-view></router-view>
    <jf-footer></jf-footer>
  </div>
</template>


<script>
import JfFooter from "@/components/JfFooter.vue";
import JfHeader from "@/components/JfHeader.vue";

export default {
  name: "",
  data() {
    return {
      storelist: [],
      indexShow: 1,
    };
  },
  components: {
    JfFooter,
    JfHeader,
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    changeNum(val) {
      if (val == 1) {
        this.$router.push("/indexContent");
      } else {
        this.$router.push("/myList?catId=0");
      }
    },
    async weiboLogin(code) {
      const { data: res } = await this.$axios.get(
        `oauth2.0/weibo/success?code=${code}`
      );
      console.log(res);
      if (res.meta.status == 200) {
        window.sessionStorage.setItem("token", res.data.token);
        window.sessionStorage.setItem("user", res.data);
        this.$router.push({ name: "Index" });
        this.$router.go(0);
      }
    },
  },
  created() {
    const code = this.$route.query.code; // code参数不为空,可能是微博登录
    if (code !== null && code !== "" && code !== undefined) {
      // 发起登录请求
      this.weiboLogin(code);
    }
    this.$axios
      .get("cateOneList", {})
      .then((res) => {
        if (res.data.meta.status !== 200) {
          return this.$message.error("获取商品列表失败！");
        }
        var goodsData = res.data.data;
        goodsData.forEach((element) => {
          let max = 6;
          let list = [];
          if (element.list.goods.length < max) {
            max = element.list.goods.length;
          }
          for (let index = 0; index < max; index++) {
            list.push(element.list.goods[index]);
          }
          element.list.goods = list;
        });
        this.storelist = goodsData;
      })
      .catch((err) => {
        console.log(err);
      });
  },
};
</script>

<style>
.t_body {
  background-color: rgb(238, 238, 238);
}
</style>
